/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLPAGE_MEM_HANDLER_H
#define PLPAGE_MEM_HANDLER_H

#include <machine/pc/memory/memhandlerinterface.h>
#include <lib/kvector.h>

/**
 * The handler to allocate pages in the memory with the physical memory
 * manager and set it into the virtual memory manager and manage the
 * allocated memory.
 */
class PLPageMemHandler : public PLMemHandlerInterface {
public:
	/**
	 * Constructor.
	 */
	PLPageMemHandler();
	/**
	 * Set the last virtual address that was allocated.
	 *
	 * @param lastVirtualAddress The last allocated virtual address.
	 */
	void setLastVirtualAddress(uint32_t lastVirtualAddress);
	/**
	 * Allocate memory with a size.
	 *
	 * @param size The size of the memory to allocate.
	 * @return Pointer to the memory.
	 */
	void *alloc(size_t size);
	/**
	 * Delete the allocated memory.
	 *
	 * @param mem The memory to delete.
	 */
	void dealloc(void *mem);
	/**
	 * Get the size of a memory pointer.
	 *
	 * @param mem The memory pointer.
	 * @return The size.
	 */
	size_t sizeOfMem(void *mem);
private:
	struct MemHeader {
		uint32_t size;
	};
	PLKVector<MemHeader *> m_empty;
	uint32_t m_lastVirtualAddress;
	uint32_t m_lastVirtualPage;
	int m_headerSize;
};

#endif
